package DesignMod;

import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;

/**
 * 懒汉模式
 */
public class Singleton {
    private static Singleton instance=new Singleton();
    private Singleton(){}
    public static Singleton getInstance(){
        return instance;
    }
}

/**
 * 饿汉模式
 */

class LazySingleton{
    private static LazySingleton instance=null;
    private LazySingleton(){}

    public static LazySingleton getInstance(){
        if(instance == null){
            synchronized (LazySingleton.class){
                if(instance == null){
                    instance=new LazySingleton();
                }
            }
        }
        return instance;
    }

}
class Main{
    public static void main(String[] args) {
        Singleton singleton=Singleton.getInstance();
        Singleton singleton1=Singleton.getInstance();
    }
}
